/**
 * @Author: 陈瑞鹏
 * @Date:   2022-10-17 11:41:11
 * @Last Modified by:   陈瑞鹏
 * @Last Modified time: 2022-10-28 09:52:34
 */
import { Code } from "../enum/code.enum";
import User from "../models/user/user.model";
import Redis from "../utils/redis";
import Result from "../utils/result";
import hero from "./hero.controller";
import sign from "./sign.controller";
import skill from "./skill.controller";
import task from "./task.controller";

/**
 * @Author: 陈瑞鹏
 * @Date:   2022-10-17 11:41:11
 * @Last Modified by:   陈瑞鹏
 * @Last Modified time: 2022-10-17 15:45:00
 */
export default class user {

  /**
   * 获取用户信息
   * @param roleId 
   */
  static async getUserInfo(roleId: number) {
    if (!roleId) {
      throw new Result(Code.Fail, '角色不存在!');
    }

    let UserRes: any = await User.findOne({ roleId });
    if (!UserRes) {
      throw new Result(Code.Fail, '角色不存在!');
    }

    if (!UserRes.status) {
      throw new Result(Code.Fail, '账号被封禁!');
    }
    await Redis.set_user_online_status(roleId);
    return UserRes;
  }

  /**
   * 登录数据初始化
   * @param roleId 
   */
  static async login_data_init(roleId: number) {
    await hero.heroInit(roleId);
    await skill.skillInit(roleId);
    await sign.signInit(roleId);
    await task.achTaskInit(roleId);
    await task.dailyTaskInit(roleId);
    await task.integralInit(roleId);
    await task.randTaskInit(roleId);
  }
}